package demo.java.java8.Lambdas.demo6;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

public class CollectorStatute {

	public static void main(String[] args) {
		
//		long howMangDishes=Test.menu.stream().collect(Collectors.counting());
//		System.out.println(howMangDishes);
//		howMangDishes=Test.menu.stream().count();
//		System.out.println(howMangDishes);
//		
//		//查找流中最大值和最小值
//		Comparator<Dish> dishCalorisComparator=Comparator.comparingInt(Dish::getCalories);
//		Optional<Dish> mostCalorieDish=Test.menu.stream().collect(Collectors.maxBy(dishCalorisComparator));
//		System.out.println(mostCalorieDish);
//		
//		//累加器
//		int totalCalories=Test.menu.stream().collect(Collectors.summingInt(Dish::getCalories));
//		System.out.println(totalCalories);
//		//reducing方法创建的收集器来计算你菜单的总热量
//		totalCalories=Test.menu.stream()
//				.collect(Collectors.reducing(0,Dish::getCalories,(i,j) -> i+j));
//		System.out.println(totalCalories);
//		
//		//求平均数
//		double avgCalories=Test.menu.stream().collect(Collectors.averagingInt(Dish::getCalories));
//		System.out.println(avgCalories);
//		
//		//链接字符串
//		String shortMenu=Test.menu.stream().map(Dish::getName).collect(Collectors.joining(""));
//		System.out.println(shortMenu);
		
		

	}
}
